# 使用python-dotenv包 https://saurabh-kumar.com/python-dotenv/#file-format
from dotenv import load_dotenv
import requests

# python核心依赖
from pprint import pprint
import os

load_dotenv()  # take environment variables from .env

# 使用os库获取环境变量 os.getenv('API_KEY')

def get_current_weather():
    city = input(f"Please enter a city name,such as Guilin: \n")
    request_url = f'https://api.openweathermap.org/data/2.5/weather?appid={os.getenv("API_KEY")}&q={city}&units=metric&lang=zh_cn'

    data = requests.get(request_url).json()
    # pprint(data)
    show_weather_data(data)

def show_weather_data(data):
    print(f"**************Output*****************")
    # 地址
    print(f"{data['sys']['country']}-{data['name']}")
    # 天气
    print(f"{int(data['main']['temp'])}°C {data['weather'][0]['description']}")